//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "GaussHermitePolynomial.h"
using namespace Cephei::QL::Math::Integrals;
#include <gen/QL/Math/Integrals/GaussianOrthogonalPolynomial.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Integrals::CGaussHermitePolynomial::CGaussHermitePolynomial (Microsoft::FSharp::Core::FSharpOption<Double>^ mu) : CGaussianOrthogonalPolynomial(CGaussHermitePolynomial::typeid)
{
    try
    {
#ifdef HANDLE
        _phGaussHermitePolynomial = NULL;
#endif
        QuantLib::Real _mu = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (mu) ? (QuantLib::Real)ValueHelper::Convert (mu->Value) : 0.0); //4
        _ppGaussHermitePolynomial = new boost::shared_ptr<QuantLib::GaussHermitePolynomial> (new QuantLib::GaussHermitePolynomial ( _mu ));
        SetGaussianOrthogonalPolynomial (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussHermitePolynomial));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Integrals::CGaussHermitePolynomial::CGaussHermitePolynomial (boost::shared_ptr<QuantLib::GaussHermitePolynomial>& childNative, Object^ owner) : CGaussianOrthogonalPolynomial(CGaussHermitePolynomial::typeid)
{
#ifdef HANDLE
	_phGaussHermitePolynomial = NULL;
#endif
	_ppGaussHermitePolynomial = &childNative;
    _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussHermitePolynomial));
}
Cephei::QL::Math::Integrals::CGaussHermitePolynomial::CGaussHermitePolynomial (QuantLib::GaussHermitePolynomial& childNative, Object^ owner) : CGaussianOrthogonalPolynomial(CGaussHermitePolynomial::typeid)
{
#ifdef HANDLE
	_phGaussHermitePolynomial = NULL;
#endif
	_ppGaussHermitePolynomial = new boost::shared_ptr<QuantLib::GaussHermitePolynomial> (&childNative);
    _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussHermitePolynomial));
    _GaussHermitePolynomialOwner = owner;
    _GaussianOrthogonalPolynomialOwner = owner;
}

Cephei::QL::Math::Integrals::CGaussHermitePolynomial::CGaussHermitePolynomial (CGaussHermitePolynomial^ copy) : CGaussianOrthogonalPolynomial(CGaussHermitePolynomial::typeid)
{
#ifdef HANDLE
	_phGaussHermitePolynomial = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGaussHermitePolynomial = new boost::shared_ptr<QuantLib::GaussHermitePolynomial> (copy->GetShared());
        _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussHermitePolynomial));
    }
}
Cephei::QL::Math::Integrals::CGaussHermitePolynomial::CGaussHermitePolynomial (System::Type^ t) : CGaussianOrthogonalPolynomial(CGaussHermitePolynomial::typeid)
{
#ifdef HANDLE
	_phGaussHermitePolynomial = NULL;
#endif
	if (!t->IsSubclassOf(CGaussHermitePolynomial::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Integrals::CGaussHermitePolynomial::CGaussHermitePolynomial (QuantLib::Handle<QuantLib::GaussHermitePolynomial>& childNative, Object^ owner)  : CGaussianOrthogonalPolynomial(CGaussHermitePolynomial::typeid)
{
	_phGaussHermitePolynomial = &childNative;
	_ppGaussHermitePolynomial = &static_cast<boost::shared_ptr<QuantLib::GaussHermitePolynomial>>(childNative.currentLink());
    _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussHermitePolynomial));
    _GaussHermitePolynomialOwner = owner;
}
Cephei::QL::Math::Integrals::CGaussHermitePolynomial::CGaussHermitePolynomial (QuantLib::Handle<QuantLib::GaussHermitePolynomial> childNative)  : CGaussianOrthogonalPolynomial(CGaussHermitePolynomial::typeid)
{
	_phGaussHermitePolynomial = &childNative;
	_ppGaussHermitePolynomial = &static_cast<boost::shared_ptr<QuantLib::GaussHermitePolynomial>>(childNative.currentLink());
    _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussHermitePolynomial));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Integrals::CGaussHermitePolynomial::CGaussHermitePolynomial (QuantLib::GaussHermitePolynomial childNative)  : CGaussianOrthogonalPolynomial(CGaussHermitePolynomial::typeid)
{
#ifdef HANDLE
	_phGaussHermitePolynomial = NULL;
#endif
	_ppGaussHermitePolynomial = new boost::shared_ptr<QuantLib::GaussHermitePolynomial> (new QuantLib::GaussHermitePolynomial (childNative));
    _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussHermitePolynomial));
}
#endif

Cephei::QL::Math::Integrals::CGaussHermitePolynomial::~CGaussHermitePolynomial ()
{
    if (_ppGaussHermitePolynomial != NULL)
    {
	    delete _ppGaussHermitePolynomial;
        _ppGaussHermitePolynomial = NULL;
    }
}
Cephei::QL::Math::Integrals::CGaussHermitePolynomial::!CGaussHermitePolynomial ()
{
    if (_ppGaussHermitePolynomial != NULL)
    {
	    delete _ppGaussHermitePolynomial;
    }
}
QuantLib::GaussHermitePolynomial& Cephei::QL::Math::Integrals::CGaussHermitePolynomial::GetReference ()
{
    if (_ppGaussHermitePolynomial == NULL) throw gcnew NativeNullException ();
	return **_ppGaussHermitePolynomial;
}
boost::shared_ptr<QuantLib::GaussHermitePolynomial>& Cephei::QL::Math::Integrals::CGaussHermitePolynomial::GetShared ()
{
    if (_ppGaussHermitePolynomial == NULL) throw gcnew NativeNullException ();
	return *_ppGaussHermitePolynomial;
}
QuantLib::GaussHermitePolynomial* Cephei::QL::Math::Integrals::CGaussHermitePolynomial::GetPointer ()
{
    if (_ppGaussHermitePolynomial == NULL) throw gcnew NativeNullException ();
	return &**_ppGaussHermitePolynomial;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::GaussHermitePolynomial>& Cephei::QL::Math::Integrals::CGaussHermitePolynomial::GetHandle ()
{
	if (_phGaussHermitePolynomial == NULL)
	{
		_phGaussHermitePolynomial = new Handle<QuantLib::GaussHermitePolynomial> (*_ppGaussHermitePolynomial);
	}
	return *_phGaussHermitePolynomial;
}
#endif
bool Cephei::QL::Math::Integrals::CGaussHermitePolynomial::HasNative () 
{
	return (_ppGaussHermitePolynomial != NULL);
}

Double Cephei::QL::Math::Integrals::CGaussHermitePolynomial::Alpha (UInt64 i)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i);
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussHermitePolynomial)->alpha ( _i );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::Integrals::CGaussHermitePolynomial::Beta (UInt64 i)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i);
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussHermitePolynomial)->beta ( _i );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::Integrals::CGaussHermitePolynomial::Mu_0::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussHermitePolynomial)->mu_0 ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::Integrals::CGaussHermitePolynomial::W (Double x)
{
    try
    {
        QuantLib::Real _x = (QuantLib::Real)ValueHelper::Convert (x);
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussHermitePolynomial)->w ( _x );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Integrals::IGaussHermitePolynomial^ Cephei::QL::Math::Integrals::CGaussHermitePolynomial_Factory::Create (Microsoft::FSharp::Core::FSharpOption<Double>^ mu)
{
    return gcnew CGaussHermitePolynomial ( mu);
}
